package project.controllers.workers.WorkerWithFile;

import java.io.FileNotFoundException;
import java.util.ArrayList;

import project.model.IGarage;
import project.model.IMaster;
import project.model.IOrder;
import textFileWorkerWrapper.TextFileWorkerWrapper;
import org.apache.log4j.Logger;
class WriterToFile {

	private static final Logger log=Logger.getLogger(WriterToFile.class);
	
	static void saveGarageList(ArrayList<IGarage> garageList,TextFileWorkerWrapper garageFile) {
		try{
		ArrayList<String> temp = new ArrayList<String>();
		
		for (IGarage garage : garageList) {
			temp.add("" + garage.getNumberGarage());
		}

		garageFile.writeToFile(temp);
		}catch(NullPointerException e){
			log.error("Collection is empty or file not found");
		}
		
	}

	 static void saveMasterList(ArrayList<IMaster> masterList,TextFileWorkerWrapper masterFile) {
		ArrayList<String> temp = new ArrayList<String>();
		try{
		
		for (IMaster master : masterList) {
			temp.add(master.getNameMaster());
		}
		masterFile.writeToFile(temp);
		}catch(NullPointerException e){
			log.error("Collection is empty or file not found");
		}
	}

	 static void saveOrderList(ArrayList<IOrder> orderList,TextFileWorkerWrapper orderFile) {
		ArrayList<String> temp = new ArrayList<String>();
		try{
		for (IOrder order : orderList) {
			temp.add(order.getNumberOrder()
					+ " "
					+ order.getFillingDate().getTime().toLocaleString()
							.substring(0, 10)
					+ " "
					+ order.getDeadlineDate().getTime().toLocaleString()
							.substring(0, 10)
					+ " "
					+ order.getBeginingDate().getTime().toLocaleString()
							.substring(0, 10) + " " + order.getPrice() + " "
					+ order.getOrderStatus() + " "
					+ order.getMaster().getNameMaster()+" "+order.getGarage().getNumberGarage());
		}

		orderFile.writeToFile(temp);
		}catch(NullPointerException e){
			log.error("Collection is empty or file not found");
		}
		
	}


}
